package com.bzr.emos.wx.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bzr.emos.wx.config.security.MyUserDetails;
import com.bzr.emos.wx.db.dao.UserDao;
import com.bzr.emos.wx.db.pojo.User;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Service
public class SecurityUserDetailsService implements UserDetailsService {


    @Resource
    private UserDao userDao;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        QueryWrapper<User> UserQueryWrapper = new QueryWrapper<>();
        UserQueryWrapper.eq("username", username);
        com.bzr.emos.wx.db.pojo.User myUser = userDao.selectOne(UserQueryWrapper);
        if (myUser == null) {
            throw new UsernameNotFoundException(username);
        }
        return new MyUserDetails(myUser);
    }

}
